package net.lainiao.routing;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import net.lainiao.MyConst;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by Administrator on 2018/7/9.
 */
public class CustomDemo {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        final Channel channel = MyConst.getChanel();
        channel.exchangeDeclare(MyConst.EName3, "direct");
        channel.queueDeclare(MyConst.QName31, false, false, true, null);
        channel.queueDeclare(MyConst.QName32, false, false, true, null);
        channel.queueBind(MyConst.QName31, MyConst.EName3, "Account.LoginOut");
        channel.queueBind(MyConst.QName32, MyConst.EName3, "Account.Login");
        DefaultConsumer consumer1 = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("用户退出记录:" + new String(body));
            }
        };
        DefaultConsumer consumer2 = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("用户登录记录:" + new String(body));
            }
        };
        channel.basicConsume(MyConst.QName31,consumer1);
        channel.basicConsume(MyConst.QName32,consumer2);
        Thread.sleep(1000000000);
    }
}
